'use strict';
import * as types from '../common/ActionTypes';
import ApiConfig from '../configs/ApiConfig';

function requestData(){
  return{
    type:types.FETCH_ZHIHU_LIST_ACTION
  };
}

function receiveData(ZhiHuData){
  return{
    type:types.RECEIVE_ZHIHU_LIST_ACTION,
    ZhiHuData
  };
}

export function fetchForZhiHuData(){
  return function (dispatch){
    //发起首次通知 开始请求了
    dispatch(requestData())
    console.log("js_Tag","start fetchForZhiHuData");
    //请求
    let MyInit_Get = {
                  method: 'GET',
                  mode: 'cors',
                  cache: 'default'
    };
    let URL = ApiConfig.ZhiHuDataURL;
    let request_get = new Request(URL,MyInit_Get);
    return fetch(request_get)
    .then(response => response.json())
    .then(json => dispatch(receiveData(json)))
    .catch((e)=>{console.log("js_Tag",e);})
  }
}
